#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long ll;
using namespace std;
ll dp[105][105];
ll daijia(int a, int b) {
    if (a==b) return 0;
    return dp[a][b];
}
int main() {
    int n;
    cin>>n;
    ll a[n];
    for (int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    memset(dp, 0, sizeof(dp));
    ll min;
    ll res=0;
    int tmp;
    ll sum;
    for (int i=0; i<n; i++) {
        for (int j=i-1; j>=0; j--) {
            min=dp[j][i-1]+dp[i][i];
            sum=a[i];
            tmp=j;
            for (int k=i-1; k>=j; k--) {
                if (dp[j][k]+dp[k+1][i]<min) {
                    min=dp[j][k]+dp[k+1][i];
                }
                sum+=a[k];
            }
            dp[j][i]=min+sum;
        }
    }
/*    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) cout<<dp[i][j]<<' ';
        cout<<endl;
    }
    cout<<endl;*/
/*    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) cout<<sum[i][j]<<' ';
        cout<<endl;
    }
    cout<<endl;*/
    cout<<dp[0][n-1]<<endl;
    return 0;
}
